package edu.gdkm.dao;

import edu.gdkm.pojo.Certification;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CertificationDao {

    // 根据ID查询
    @Select("SELECT * FROM Certifications WHERE certification_id = #{certificationId}")
    Certification selectById(Integer certificationId);

    // 根据简历ID查询
    @Select("SELECT * FROM Certifications WHERE resume_id = #{resumeId} ORDER BY issue_date DESC")
    List<Certification> selectByResumeId(Integer resumeId);

    // 查询所有
    @Select("SELECT * FROM Certifications")
    List<Certification> selectAll();

    // 新增
    @Insert("INSERT INTO Certifications(resume_id, name, issuer, issue_date, expiration_date, credential_id, url) " +
            "VALUES(#{resumeId}, #{name}, #{issuer}, #{issueDate}, #{expirationDate}, #{credentialId}, #{url})")
    @Options(useGeneratedKeys = true, keyProperty = "certificationId")
    int insert(Certification certification);

    // 更新
    @Update("UPDATE Certifications SET resume_id = #{resumeId}, name = #{name}, issuer = #{issuer}, " +
            "issue_date = #{issueDate}, expiration_date = #{expirationDate}, credential_id = #{credentialId}, " +
            "url = #{url} WHERE certification_id = #{certificationId}")
    int update(Certification certification);

    // 删除
    @Delete("DELETE FROM Certifications WHERE certification_id = #{certificationId}")
    int delete(Integer certificationId);
    
    // 根据简历ID删除
    @Delete("DELETE FROM Certifications WHERE resume_id = #{resumeId}")
    int deleteByResumeId(Integer resumeId);
}
    